//
//  LoginPromtView.m
//  Router
//
//  Created by teki on 15/10/20.
//  Copyright © 2015年 dc. All rights reserved.
//

#import "LoginPromtView.h"

@interface LoginPromtView ()

@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIButton *loginAgainButton;

@property (weak, nonatomic) IBOutlet UIButton *registerNowButton;
@end


@implementation LoginPromtView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


+ (LoginPromtView *)loadViewFromNib
{
    NSArray *array = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil];
    if ([array count] >0) {
        return array[0];
    }
    return nil;
}


- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
    }
    return self;
}


- (void)awakeFromNib
{
    [self initUI];
}


- (void)initUI
{
    
    self.backgroundColor = [UIColor clearColor];
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.contentView.layer.cornerRadius = 5.0f;
    self.contentView.layer.masksToBounds = YES;

    UIColor *textColor = [UIColor colorWithHexString:@"#ff7800"];
    self.titleLabel.textColor = textColor;
    
    self.loginAgainButton.layer.cornerRadius = 5.0f;
    self.loginAgainButton.layer.masksToBounds = YES;
    [self.loginAgainButton setTitle:@"重新登录" forState:UIControlStateNormal];
    [self.loginAgainButton setBackgroundImage:[UIImage imageWithColor:NavgationBarBackgroundColor] forState:UIControlStateNormal];
    
    [self.registerNowButton setTitleColor:[UIColor colorWithHexString:@"#77c66d"] forState:UIControlStateNormal];
    
}


- (void)show
{
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    [self makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo([UIApplication sharedApplication].keyWindow);
    }];
//    CAKeyframeAnimation *popAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
//    popAnimation.duration = 0.4;
//    popAnimation.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.01f, 0.01f, 1.0f)],
//                            [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1f, 1.1f, 1.0f)],
//                            [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9f, 0.9f, 1.0f)],
//                            [NSValue valueWithCATransform3D:CATransform3DIdentity]];
//    popAnimation.keyTimes = @[@0.2f, @0.5f, @0.75f, @1.0f];
//    popAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
//                                     [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
//                                     [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
//    [self.contentView.layer addAnimation:popAnimation forKey:nil];
}


- (void)hidden
{
//    CAKeyframeAnimation *hideAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
//    hideAnimation.duration = 0.4;
//    hideAnimation.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1f, 1.1f, 1.0f)],
//                             [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0f, 1.0f, 1.0f)],
//                             [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.00f, 0.00f, 0.00f)]];
//    hideAnimation.keyTimes = @[@0.2f, @0.5f, @0.75f];
//    hideAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
//                                      [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
//                                      [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
//    hideAnimation.delegate = self;
//    [self.contentView.layer addAnimation:hideAnimation forKey:nil];
    [self removeFromSuperview];

}


- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    [self removeFromSuperview];
}


- (IBAction)loginAgainButtonPressed:(id)sender {
    [self hidden];
}


- (IBAction)registerButtonPressed:(id)sender {
    [self hidden];
}

@end
